package com.itlong.cloud.commons;

import com.itlong.cloud.noncore.commons.ITimeTaskOfOperationLogServiceClient;
import com.itlong.cloud.utils.date.DateUtil;
import org.slf4j.Logger;import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.RestController;

import java.util.Calendar;

/**
 * <desc>
 *      定期清理数据定时任务(包含通行记录，指令，操作日志等等)
 * </desc>
 *
 * @createDate 2019/09/04
 */
@EnableScheduling // 启用定时任务
@RestController
public class RegularCleanDataTimeTask {

    private static Logger LOG = LoggerFactory.getLogger(RegularCleanDataTimeTask.class);

    @Autowired
    private ITimeTaskOfOperationLogServiceClient iTimeTaskOfOperationLogServiceClient;

    /**
     * <desc>
     *      定时任务定期清理数据
     *      转移3个月前通行记录数据，表中删除，优化查询，同时只保留一周内的设备指令数据，1个月内的人脸识别增量数据，对于开发者操作日志、机器人app操作日志、用户登录日志三个表中的数据，目前累积不多，
     *      如有必要，后续再做处理
     * </desc>
     *
     * @author wangzhi
     * @createDate 2019/09/04
     */
    @Scheduled(cron = "0 20 5 * * ?")   // 每天凌晨5点20执行
    public void timeTaskRegularCleanData() {
        try {
            iTimeTaskOfOperationLogServiceClient.regularCleanData();
            //LOG.info("【定时任务】定期清理数据成功，当前时间：" + DateUtil.format(Calendar.getInstance(), "yyyy-MM-dd HH:mm:ss"));
        } catch (Exception e) {
            LOG.info("【定时任务】定期清理数据失败，当前时间：" + DateUtil.format(Calendar.getInstance(), "yyyy-MM-dd HH:mm:ss:"), e);
        }
    }

}
